{echo:JS::import("form")}
{echo:JS::import('dialog?skin=tinysimple');}
{echo:JS::import('dialogtools');}
<link type="text/css" rel="stylesheet" href="{url:#css/ucenter.css}" />
<div class="container clearfix">
	{widget:name=sub_navs action=ucsidebar sidebar=$sidebar act=$actionId}
	<div class="content clearfix uc-content">
		<h1 class="title"><span>账户金额管理：</span></h1>
		<table class="simple">
			<tr>
				<td>消费积分(冻结)</td>
				<td>消费积分(可用)</td>
				<td>分享额度(总额)</td>
				<td>分享额度(已用)</td>
				<td>账户余额</td>
				<td>云积分</td>
				<td>通用积分</td>
				<td>消费券</td>
			</tr>
			<tr class="red">
				<td>{$customer['dj_xfjf']|'0.00'}</td>
				<td>{$customer['ok_xfjf']|'0.00'}</td>
				<td>{$customer['extend_je']|'0'}</td>
				<td>{$customer['extend_used_je']|'0.00'}</td>
				<td>{$customer['balance']|'0.00'}</td>
				<td>{$customer['cloud_point']|'0.00'}</td>
				<td>{$customer['currency_point']|'0.00'}</td>
				<td>{$customer['voucher']|'0.00'}</td>
			</tr>
		</table>
		
		<div class="box p15 mt10 clearfix"> 
			<span class="fr">
				<!-- 
				<a href="javascript:;" id="recharge-btn" class="btn btn-main btn-mini">充值</a>
				-->
				  
				<a href="javascript:;" id="zz-btn" class="btn btn-main btn-mini">转账</a> 
				
				<a href="javascript:;" id="zh-btn" class="btn btn-main btn-mini">兑换</a>
				{set:$is_withdraw = intval(Common::getConfigJJsetValue('jjset_txflag'))}
				{if:$is_withdraw==1}
				<a href="javascript:;" id="withdraw-btn" class="btn btn-main btn-mini">提现</a>
				{/if}
				
			</span>
		</div>
		
		<div class="mt10 tab">
			<ul class="tab-head">
				<!-- 
				<li>日志记录<i></i></li>
				-->
				
				<!-- 
				<li>充值扣款<i></i></li>
				<li>转账记录<i></i></li>
				<li>兑换录记<i></i></li>
				<li>提现记录<i></i></li>
				<li>奖金明细<i></i></li>
				-->
			</ul>
			<div class="tab-body">
				<!-- 
				<div>
					<table class="simple">
						<tr>
							<th width="160">时间</th> <th width="120">存入 / 取出</th><th width="120">余额</th> <th >备注</th>
						</tr>
						{query:name=balance_log where=user_id eq $user[id] order=id desc page=1 id=$obj}
						<tr class="{if:$key%2==1}odd{else:}even{/if}">
							<td>{$item['time']}</td> <td>{$item['amount']}</td><td>{$currency_symbol}{$item['amount_log']}</td><td>{$item['note']}</td>
						</tr>
						{/query}
					</table>
					<div class="page-nav f12">{echo:$obj->pagebar()}</div>
				</div>
				-->
				
				
				
				<!-- 充值扣款 -->
				<!-- 
				<div>
					<table class="simple">
						<tr>
							<th style="width:140px">时间</th>
							<th>金额</th>
							<th>操作类型</th>
							<th>账户类型</th>
							<th>操作人</th>
						</tr>
						{query:name=recharge where=user_id eq '$user[id]' page=1 order=id desc id=$zz}
						<tr class="{if:$key%2==1}odd{else:}even{/if}" align='center'>
							<td>{$item['create_time']}</td> 
							<td>{$item['je']}</td>
							<td>
								{if:$item['type']==0}
					        		<b class="green">充值</b>
					        	{elseif:$item['type']==1}
					        		<b class="red">扣款</b>
					        	{/if}
							</td>
							<td>{echo:Common::get_account_name($item['account_type'])}</td>
							<td>{$item['admin']}</td>
						</tr>
						{/query}
					</table>
					<div class="page-nav f12">{echo:$zz->pagebar()}</div>
				</div>
				-->
				<!-- 转账 -->
				<!-- 
				<div>
					<table class="simple">
						<tr>
							<th style="width:140px">时间</th>
							<th style="width:90px">转出账号</th>
							<th style="width:90px">接收账号</th>
							<th style="width:120px">转账金额</th>
							<th>备注</th>
						</tr>
						{query:name=zz where=uname eq '$user[name]' or toname eq '$user[name]' page=1 order=id desc id=$zz}
						<tr class="{if:$key%2==1}odd{else:}even{/if}">
							<td>{$item['time']}</td> 
							<td>{$item['uname']}</td>
							<td>{$item['toname']}</td>
							<td>{$currency_symbol}{$item['je']}</td>
							<td>{$item['bz']}</td>
						</tr>
						{/query}
					</table>
					<div class="page-nav f12">{echo:$zz->pagebar()}</div>
				</div>
				-->
				<!-- 转换 -->
				<!-- 
				<div>
					<table class="simple">
						<tr>
							<th width="140">转换时间</th> <th width="120">转换方式</th><th width="120">转换金额</th> <th width="120">现金余额</th>
						</tr>
						{query:name=zh where=user_id eq $user[id] order=id desc page=1 id=$obj}
						<tr class="{if:$key%2==1}odd{else:}even{/if}">
							<td>{$item['zh_time']}</td> <td>{$item['zh_lx']}</td><td>{$currency_symbol}{$item['zh_money']}</td><td>{$currency_symbol}{$item['ye']}</td>
						</tr>
						{/query}
					</table>
					<div class="page-nav f12">{echo:$obj->pagebar()}</div>
				</div>
				-->
				<!-- 提现 -->
				<!-- 
				<div>
					<table class="simple">
						<tr>
							<th width="120">时间</th><th width="80">申请金额</th><th width="60">手续费</th><th width="80">实提金额</th> <th width="50">姓名</th><th width="140">金融机构</th> <th width="140">金融账号</th> <th width="50">状态</th>
						</tr>
						{query:name=withdraw where=user_id eq $user[id] order=id desc page=1 id=$withdraw}
						<tr class="{if:$key%2==1}odd{else:}even{/if} {if:$item['status']==2}noborder{/if}">
							<td>{$item['time']}</td> <td >{$currency_symbol}{$item['sq_money']}</td><td >{$currency_symbol}{$item['txf']}</td><td >{$currency_symbol}{$item['amount']}</td><td>{$item['name']}</td><td>{$item['type_name']}</td> <td >{$item['account']}</td> <td>{if:$item['status']==0}<span class="red">处理中</span>{elseif:$item['status']==1}<b class="green">提现成功</b>{else:}<span class="gray">失败</span>{/if}</td>
						</tr>
						{if:$item['status']==2}
						<tr>
							<td colspan="8" style="padding-left:20px;"><p><span class="red">处理意见：</span>{$item['re_note']} </p></td>
						</tr>
						{/if}
						{/query}
					</table>
					<div class="page-nav f12">{echo:$withdraw->pagebar()}</div>
				</div>
				-->
				<!-- 明细 -->
				<!-- 
				<div>
					<table class="simple">
						<tr>
							<th width="120">时间</th><th width="100">来源</th><th width="100">推荐奖</th><th width="100">推3代奖</th><th width="100">销售提成</th><th width="100">购物提成</th><th width="100">重消</th><th width="100">合计</th>
						</tr>
						{query:name=jjmx where=user_id eq $user[id] order=id desc page=1 id=$jjmx}
						<tr class="{if:$key%2==1}odd{else:}even{/if} {if:$item['status']==2}noborder{/if}">
							<td>{$item['jjtime']}</td><td>{$item['from']}</td> <td >{$currency_symbol}{$item['tjj']}</td><td >{$currency_symbol}{$item['tjdsj']}</td><td >{$currency_symbol}{$item['xstc']}</td><td >{$currency_symbol}{$item['gwtc']}</td><td >{$currency_symbol}{$item['cx']}</td><td >{$currency_symbol}{$item['hj']}</td>
						</tr>
						{/query}
					</table>
					<div class="page-nav f12">{echo:$jjmx->pagebar()}</div>
				</div>
				-->
			</div>
		</div>
	</div>
</div>
<div id="recharge-dialog" class="hidden">
	<form action="{url:/payment/dopay}" method="post" target="_blank" callback="close_dialog">
		<table class="form" style="width:500px;">
			<tr>
				<td class="label">充值金额：</td>
				<td><input type="text" name="recharge"  pattern="float" alt="最小金额不小于0.01"> <label></label></td>
			</tr>
			<tr>
				<td class="label">支付方式：</td>
				<td><select name="payment_id">
					{query:name=payment as py fields=py.* join= left join pay_plugin as pp on py.plugin_id eq pp.id where=pp.class_name ne 'balance' and pp.class_name ne 'received' order=sort desc}
					<option value="{$item['id']}">{$item['pay_name']}</option>
					{/query}
				</select></td>
			</tr>
			<tr>
				<td colspan="2" class="tc"><input type="submit" class="btn" value="立刻充值"></td>
			</tr>
		</table>
	</form>
</div>
<div id="zh-dialog" class="hidden">
	<!-- 
	<table class="simple">
		<tr><td>现金币</td><td>借款币</td><td>购物币</td><td>重消币</td><td>信用币</td><td>学习币</td></tr>
		<tr class="red"><td>{$customer['balance']|'0.00'}</td><td>{$customer['jkb']|'0.00'}</td><td>{$customer['gwb']|'0'}</td><td>{$customer['cx']|'0.00'}</td><td>{$customer['xyb']|'0'}</td><td>{$customer['xxb']|'0'}</td></tr>
	</table>
	-->
	<form id="zh_form" action="{url:/ucenter/zh}" method="post" target="_blank" callback="submit_zh">
		<table class="form" style="width:600px;">
			<tr>
				<td >兑换方式：</td>
				<td>
				<select name="zh_type" id="zh_type" onchange="sel_change_txt()">
					<option value="0">账户余额 兑换 消费券</option>
					<option value="1">通用积分 兑换 消费券</option>
					<option value="2">通用积分 兑换 可用积分</option>
					<option value="3">可用积分 兑换 通用积分</option>
				</select>&nbsp;&nbsp;&nbsp;<span class="f12 red">兑换比例 1:1</span>
				
				</td>
			</tr>
			<tr>
				<td >兑换金额：</td>
				<td><input type="text" name="zh_amount" id="zh_amount" pattern="float" min='1' alt="最低金额不小于1"> <label></label></td>
			</tr>
			<tr>
				<td >二级密码：</td>
				<td><input type="password" name="pass2" id="pass2" pattern="required" alt="输入二级密码"> <label></label></td>
			</tr>
			<tr>
				<td colspan="2" class="tc">
					<input type="submit" class="btn btn-main" value="提交" id="btn_zh">
				</td>
			</tr>
		</table>
	</form>
</div>
<!-- 转账 -->
<div  id="zz-dialog" class="hidden">
<form id="zz_form" action="{url:/ucenter/zz}" method="post" target="_blank" callback="submit_zz">
	<table class="form" style="width:600px;">
		<tr>
			<td class="label">通用积分：</td>
			<td> <label class="f18 red">{$currency_symbol}{$customer['currency_point']}</label></td>
		</tr>
		<tr>
			<td class="label">接收账号：</td>
			<td><input type="text" name="zz_toname" id="zz_toname" class="" pattern="required" placeholder='输入接受账号' alt="输入接收账号" onblur="show_tip(this)"> <label></label></td>
		</tr>
		<tr>
			<td class="label">转账额度：</td>
			<td><input type="text" id="zz_amount" name="zz_amount" class=""  pattern="float" min="1" placeholder='不能小于1' alt="不能小于1"> <label><!-- 不能小于10元 --></label></td>
		</tr>
		<tr>
			<td class="label">备注：</td>
			<td><textarea name="zz_bz"></textarea>
			<label></label></td>
		</tr>
		<tr>
			<td class="label">短信验证码：</td>
			<td><input type="text" name="validate_code" id="validate_code" pattern="required" placeholder="输入短信验证码" alt="输入短信验证码"> <label></label>
				<input type="button" class="btn btn-main" value="获取短信验证码" onclick="get_validate_code()"/>
			</td>
		</tr>
		<tr>
			<td class="label">交易密码：</td>
			<td><input type="password" name="zz_pass2" id="zz_pass2" pattern="required" placeholder="输入交易密码" alt="输入交易密码"> <label></label></td>
		</tr>
		<!-- 
		<tr>
			<td class="tc red f16" colspan="2">请认真核对好接收会员的正确编号！</td>
		</tr>
		-->
		<tr>
			<input type="hidden" name="hid_zz_from_user_id" value="{$user['id']}"/>
			<td colspan="2" class="tc"><input type="submit" class="btn btn-main" value="开始转账" id="btn_zz"></td>
		</tr>
	</table>
</form>
</div>
<div  id="withdraw-dialog" class="hidden">
	<form id="withdraw_form" action="{url:/ucenter/withdraw}" method="post" target="_blank" callback="submit_withdraw">
		<table class="form" style="width:600px;">
			<tr>
				<td class="label">账户金额：</td>
				<td> <label class="f18 red">{$currency_symbol}{$customer['balance']}</label></td>
			</tr>
			<tr>
				<td class="label">提现金额：</td>
				<td><input type="text" id="w_amount" name="amount" class="small"  pattern="int" min="10" alt="提现金额至少为100且为10的倍数"> <label></label></td>
			</tr>
			<tr>
				<td class="label">姓名：</td>
				<td><input type="text" id="w_name" name="name" readonly  pattern="required" placeholder="开户对应的用户名" alt="开户对应的用户名" value="{$user['real_name']}"> <label></label>
				</td>
			</tr>
			<tr>
				<td class="label">&nbsp;&nbsp;</td>
				<td>
					姓名不可编辑，若为空，请到个人信息中心完善资料
				</td>
			</tr>
			<tr>
				<td class="label">开户银行地址：</td>
				<td><input type="text" id="w_type_name" name="type_name" value="{$user['bank']}"  pattern="required" placeholder="如（中国银行某某支行）" alt="如（中国银行某某支行）"> <label></label></td>
			</tr>
			<tr>
				<td class="label">银行账号：</td>
				<td><input type="text" id="w_account" name="account" value="{$user['bank_kh']}"  pattern="required" placeholder="如（支付宝账号、银行账号）" alt="如（支付宝账号、银行账号）"> <label></label></td>
			</tr>
			<tr>
				<td  class="label">交易密码：</td>
				<td><input type="password" name="pass2" id="pass2" pattern="required" alt="输入交易密码" placeholder="输入交易密码"> <label></label></td>
			</tr>
			<tr>
				<td colspan="2" class="tc"><input type="submit" class="btn btn-main" value="申请提现" id="btn_withdraw"></td>
			</tr>
		</table>
	</form>
</div>
<script type="text/javascript">
	$("#recharge-btn").on("click",function() {
		art.dialog({id:'recharge-dialog',title:'在线充值',content:document.getElementById('recharge-dialog'),lock:true});
	});
	$("#withdraw-btn").on("click",function() {
		art.dialog({id:'withdraw-dialog',title:'提现申请',content:document.getElementById('withdraw-dialog'),lock:true});
	});
	$("#zh-btn").on("click",function() {
		art.dialog({id:'zh-dialog',title:'兑换',content:document.getElementById('zh-dialog'),lock:true});
	});
	$("#zz-btn").on("click",function() {
	art.dialog({id:'zz-dialog',title:'转账',content:document.getElementById('zz-dialog'),lock:true});
});
	function close_dialog(e){
		if(!e)art.dialog({id:'recharge-dialog'}).close();
	}
	function submit_withdraw(e){
		if(!e){
			var name = $("#w_name").val();
			var type_name = $("#w_type_name").val();
			var account = $("#w_account").val();
			var amount = $("#w_amount").val();
			var pass2 = $("#pass2").val();
			
			if(amount % 10 != 0 || amount <100)
			{
				alert("提现金额必须大于等于100且为10的倍数");
				return false;
			}
			
			$("#btn_withdraw").attr("disabled", true);
			$.get("{url:/ucenter/withdraw}",{name:name,type_name:type_name,pass2:pass2,account:account,amount:amount},function(data){
				if(data['status']=='success'){
					art.dialog({id:'withdraw-dialog'}).close();
					art.dialog.tips("<p class='"+data['status']+"'>"+data['msg']+"</p>",2);
            		setTimeout("tools_reload()",2000);
					//window.location.href = "{url:/ucenter/account/rand/}"+Math.random()+"#tab-3";
            		window.location.href = "{url:/ucenter/withdraw_list}";
				}else{
					alert(data['msg']);
					$("#btn_withdraw").attr("disabled", false);
				}
			},'json');
		}
		return false;
	}
	function submit_zh(e){
		if(!e){
			var zh_type = $("#zh_type").val();
			var pass2   = $("#pass2").val();
			var amount  = $("#zh_amount").val();
			
			$("#btn_zh").attr("disabled", true);
			
			$.get("{url:/ucenter/zh}",{zh_type:zh_type,pass2:pass2,amount:amount},function(data){
				if(data['status']=='success')
				{
					art.dialog({id:'zh-dialog'}).close();
					art.dialog.tips("<p class='"+data['status']+"'>"+data['msg']+"</p>",2);
            		setTimeout("tools_reload()",2000);
					//window.location.href = "{url:/ucenter/account/rand/}"+Math.random()+"#tab-2";
            		window.location.href = "{url:/ucenter/exchange_list}";
				}
				else
				{
					alert(data['msg']);
					$("#btn_zh").attr("disabled", false);
				}
			},'json');
		}
		return false;
	}
	
	
	function submit_zz(e)
	{
		if(!e)
		{
			var fields = $("#zz_form").serializeArray();
			
			$("#btn_zz").attr("disabled", true);
			
			$.get("{url:/ucenter/zz}",fields,function(data){
				if(data['status']=='success'){
					art.dialog({id:'zz-dialog'}).close();
					art.dialog.tips("<p class='"+data['status']+"'>"+data['msg']+"</p>",2);
	            	setTimeout("tools_reload()",2000);
	            //window.location.href = "{url:/ucenter/account/rand/}"+Math.random()+"#tab-1";
	            window.location.href = "{url:/ucenter/zz_list}";
				}else{
					alert(data['msg']);
					$("#btn_zz").attr("disabled", false);
				}
			},'json');
		}
		return false;
	}
	
	
	function sel_change_txt()
	{
		var zh_type = $("#zh_type").val();
		$("#zh_amount").attr("class","")
		$("#zh_amount").next("label").attr("class","").text("");
		if(zh_type == 3)
		{
			$("#zh_amount").attr("min","100").attr("alt","兑换金额至少为100且必须为100的倍数");
			$("#zh_type").next("span").text('兑换比例 1:0.85');
		}
		else
		{
			$("#zh_type").next("span").text('兑换比例 1:1');
			$("#zh_amount").attr("min","1").attr("alt","最低金额不小于1");
		}
	}
	
	function show_tip(obj)
	{
		var toname = $.trim(obj.value);
		if(toname != '')
		{
			$(obj).next("label").html('');
			$.post("{url:/ajax/get_real_name_by_name}",{from_user_id:{$user['id']},toname:toname},function(result){
				
				if(result['status']=='success')
				{
					$(obj).next("label").html("真实姓名："+result['msg']);
				}
				else
				{
					$(obj).next("label").html(result['msg']);
				}
			},'json');
		}
	}
	
	function get_validate_code()
	{
		var mobile = "{$user['name']}";
		/*
		var mobile = $.trim($("#uname").val());
		
		if(mobile == '')
		{
			alert('手机号码不能为空');
			return;
		}
		
		var mobile_pattern = /^1[3-9]\d{9}$/;
		if(!mobile_pattern.test(mobile))
		{
			alert('手机号码不合法');
			return;
		}
		*/
		
		$("#btn_get_validate").attr("disabled", true);
		$.post("{url:/simple/sms_send}",{mobile:mobile},function(result){
		      alert(result);
		      $("#btn_get_validate").attr("disabled", false);
		  });
	}
</script>
